<?php
class SemesterApartement extends AppModel {

	var $name = 'SemesterApartement';
	var $primaryKey = 'semester_apartement_id';
	var $validate = array(
		'semester_id' => VALID_NOT_EMPTY,
		'apartement_id' => VALID_NOT_EMPTY,
		'gender' => VALID_NOT_EMPTY,
		'language_id' => VALID_NOT_EMPTY,
	);

	var $belongsTo = array(
					'Semester' =>
						array('className' => 'Semester',
									'foreignKey' => 'semester_id'),
					'Apartement' =>
						array('className' => 'Apartement',
									'foreignKey' => 'apartement_id'),
					'Language' =>
						array('className' => 'Language',
									'foreignKey' => 'language_id')
				);

	function getSemesterApartementList($semesterId) {
		$semesters = $this->query("SELECT sa.semesterApartement_id, a.apartementNumber FROM semester_apartements sa, apartements a where a.apartement_id = sa.apartement_id AND sa.semester_id = '$semesterId'");
		$semesterApartementList = array();
		foreach($semesters as $semester) {
			$semesterApartementId = $semester['sa']['semesterApartement_id'];
			$apartementNumber = $semester['a']['apartementNumber'];
			$semesterApartementList[$semesterApartementId] = $apartementNumber;
		}
		return $semesterApartementList;
	}

}
?>
